package com.Controller;

import com.Service.WeiduService;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Weidu")
public class WeiduController {
    @Autowired
    private WeiduService weiduService;

    //未读消息的添加
    @PostMapping("/add")
    public R add(@RequestBody Map<String, String> Map_All) {
        String sendertel=Map_All.get("sendertel");
        String recipienttel=Map_All.get("recipienttel");
        String content=Map_All.get("content");
        return new R(true,weiduService.add(sendertel,recipienttel,content));
    }
    //查看未读消息
    @PostMapping("/selectWeidu")
    public R weidu(@RequestBody Map<String, String> Map_All) {
        String tel=Map_All.get("tel");
        return new R(true,weiduService.select(tel));
    }
    //查看消息后删除
    @PostMapping("/del")
    public R del(@RequestBody Map<String, String> Map_All) {
        String sendertel=Map_All.get("sendertel");
        String recipienttel=Map_All.get("recipienttel");
        return new R(true,weiduService.del(sendertel,recipienttel));
    }
    //weiduListAdd
    @PostMapping("/weiduListAdd")
    public R weiduListAdd(@RequestBody Map<String, String> Map_All) {
        String sendertel=Map_All.get("sendertel");
        String recipienttel=Map_All.get("recipienttel");
        return new R(weiduService.weiduListAdd(sendertel,recipienttel,"")>0);
    }
}
